<?php
/*
@author: wjf
@contact: Hurrican
@software: PhpStorm
@create: 2022/8/9 9:12
*/
declare(strict_types=1);
namespace app\store\controller;

use app\common\model\Advertising as AdvertisingModel;
use think\App;
use think\response\Json;
use app\store\service\Advertising as AdvertisingService;


class Advertising extends Controller{

    private $advertisingService;
    public function __construct(App $app,AdvertisingService $advertisingService)
    {
        parent::__construct($app);
        $this->advertisingService = $advertisingService;
    }


    //新增
    public function save():Json
    {
        $params = $this->request->post();
        $this->validate(
            $params,
          [
              'type' => 'integer',  //默认传1
              'value' => 'require',  //json [{"img_id":123,"jump_url":""},{"img_id":123,"jump_url":""}]
          ]
        );
        $res = $this->advertisingService->save($params);
        if(empty($res)){
            $this->renderError('新增失败');
        }
        return $this->renderSuccess();
    }



    //详情
    public function detail():Json
    {
        $params = $this->request->get();
        $this->validate(
            $params,
            [
                'type' => 'integer',
            ]
        );
        $model = new AdvertisingModel();
        $ad = $model->detail($params['type'] ?? 1);
        return $this->renderSuccess($ad);
    }


}